5 Assignment 4: LAGOS Spatial Analyses 1
title: “LAGOS Spatial Analysis” author: “Matthew Ross, completed by Samantha Clark” date: “2/23/2022” output: html_document editor_options: chunk_output_type: console
5.1 LAGOS Analysis
5.1.1 Loading in data
#install.packages(c("RApiSerialize", "LAGOSNE", 'USAboundaries'))
#LAGOSNE::lagosne_get(dest_folder = LAGOSNE:::lagos_path())5.1.1.1 First download and then specifically grab the locus (or site lat longs)
# #Lagos download script
#LAGOSNE::lagosne_get(dest_folder = LAGOSNE:::lagos_path())
#Load in lagos
lagos <- lagosne_load()## Warning in (function (version = NULL, fpath = NA) : LAGOSNE version unspecified,
## loading version: 1.087.3
#Grab the lake centroid info
lake_centers <- lagos$locus5.1.1.2 Convert to spatial data
#Look at the column names
#names(lake_centers)
#Look at the structure
#str(lake_centers)
#View the full dataset
#View(lake_centers %>% slice(1:100))
spatial_lakes <- st_as_sf(lake_centers,coords=c('nhd_long','nhd_lat'),
crs=4326) %>%
st_transform(2163)
#Subset for plotting
subset_spatial <- spatial_lakes %>%
slice(1:100)
subset_baser <- spatial_lakes[1:100,]
#Dynamic mapviewer
mapview(subset_spatial)5.1.1.3 Subset to only Minnesota
states <- us_states()
#Plot all the states to check if they loaded
#mapview(states)
minnesota <- states %>%
filter(name == 'Minnesota') %>%
st_transform(2163)
#Subset lakes based on spatial position
minnesota_lakes <- spatial_lakes[minnesota,]
#Plotting the first 1000 lakes
minnesota_lakes %>%
arrange(-lake_area_ha) %>%
slice(1:1000) %>%
st_transform(4326) %>%
mapview()mapviewOptions(fgb = F)5.2 In-Class work
5.2.1 1) Show a map outline of Iowa and Illinois (similar to Minnesota map upstream)
#subset to Iowa and Illinois
IAandIL <- states %>%
filter(name %in% c('Iowa', 'Illinois')) %>%
st_transform(2163)
#create a map
mapview(IAandIL)5.2.2 2) Subset LAGOS data to these sites, how many sites are in Illinois and Iowa combined? How does this compare to Minnesota?
#Subset lakes based on spatial position
IAandIL_lakes <- spatial_lakes[IAandIL,]
nrow(IAandIL_lakes)## [1] 16466
nrow(minnesota_lakes)## [1] 29038
Illinois and Iowa have 16,466 sites. Minnesota has 29,038 sites. This is nearly double the number of sites, compared to Illinois and Iowa combined.
5.2.3 3) What is the distribution of lake size in Iowa vs. Minnesota?
- Here I want to see a histogram plot with lake size on x-axis and frequency on y axis (check out geom_histogram)
- make histogram log
# subset to just Iowa data
iowa <- states %>%
filter(name == 'Iowa') %>%
st_transform(2163)
# create spatial lake data for Iowa
iowa_lakes <- spatial_lakes[iowa,]
iowa_lakes$state <- 'Iowa'
# get a lakes set for Minnesota
minnesota_lakes$state <- 'Minnesota'
#Combine Iowa and Minnesota Data
IAandMN_lakes <- bind_rows(iowa_lakes, minnesota_lakes)
names(IAandMN_lakes)## [1] "lagoslakeid" "nhdid" "gnis_name"
## [4] "lake_area_ha" "lake_perim_meters" "nhd_fcode"
## [7] "nhd_ftype" "iws_zoneid" "hu4_zoneid"
## [10] "hu6_zoneid" "hu8_zoneid" "hu12_zoneid"
## [13] "edu_zoneid" "county_zoneid" "state_zoneid"
## [16] "elevation_m" "state" "geometry"
#Plot the lakes
ggplot(IAandMN_lakes) + aes(x=lake_area_ha, fill = state) +geom_histogram()+ scale_x_log10() + ylab('Frequency') +xlab('Lake Size in Hectares') + facet_wrap(vars(state))## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

There are more lakes in Minnesota than in Iowa, but the distribution of lakes is similar. For both states there are a greater number of smaller lakes, and a smaller number of large lakes.
5.2.4 4) Make an interactive plot of lakes in Iowa and Illinois and color them by lake area in hectares
# Use mapview to create an interactive plot of lakes
mapview(IAandIL_lakes, zcol = "lake_area_ha", at = c(0, 5, 10, 100, 250, 500, 750, 1000, 5000, 10000))